﻿using System;
using Glue;
using Xunit;

namespace GlueTests.MapperVerificationTests
{
    public class When_mapping_between_arrays_of_nested_types
    {
        public class DomainPerson
        {
            public DomainAddress[] Addresses { get; set; }
        }
        public class DomainAddress
        {
            public String NormalProperty { get; set; }
            public String PropertyThatDoesntSet { get { return null;} set { return;} }
        }

        public class GuiPerson
        {
            public GuiAddress[] Addresses { get; set; }
        }
        public class GuiAddress
        {
            public String NormalProperty { get; set; }
            public String PropertyThatDoesntSet { get { return null; } set { return; } }
        }

        //[Fact] //TODO: We do not suppert this for the time being
        public void Should_verify_nested_relation()
        {
            var addressMapping = new Mapping<DomainAddress, GuiAddress>();
            addressMapping.Relate(domain => domain.NormalProperty, gui => gui.NormalProperty);
            var verification = GetVerificationTowardsRight(addressMapping);

            verification.AssertMapsCorrectlyTowards(new GuiPerson());
        }

        //[Fact] //TODO: We do not suppert this for the time being
        public void Should_not_verify_if_nested_relation_fails()
        {
            var addressMapping = new Mapping<DomainAddress, GuiAddress>();
            addressMapping.Relate(domain => domain.PropertyThatDoesntSet, gui => gui.PropertyThatDoesntSet);
            var verification = GetVerificationTowardsRight(addressMapping);

            verification.AssertMapsCorrectlyTowards(new GuiPerson());
            Assert.Throws(typeof(GlueException),()=> verification.AssertMapsCorrectlyTowards(new GuiPerson()));
        }

        private IMapperVerification<DomainPerson, GuiPerson> GetVerificationTowardsRight(Mapping<DomainAddress, GuiAddress> addressMapping)
        {

            var mapping = new Mapping<DomainPerson, GuiPerson>();
            mapping.Relate(domain => domain.Addresses, gui => gui.Addresses, addressMapping);

            return mapping.GetMapperVerification();
        }
    }
}
